<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="版本">
              <a-input placeholder="输入版本号" v-model="queryParam.version"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-button @click="() => {this.queryPage()}" type="primary">查询</a-button>
            <a-button @click="() => queryParam = {}" style="margin-left: 8px">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <v-table
      bordered
      ref="table"
      :data="loadData"
      :columns="columns"
    >
      <span slot="action" slot-scope="{row,text}">
        <span v-action="'sys:user:update'">
          <a :href="row.url" download>下载</a>
          <a-divider type="vertical" />
        </span>
        <span v-action="'sys:user:del'">
          <a-popconfirm title="是否删除该版本" @confirm="deleteItem(row)" okText="是" cancelText="否">
            <a-icon slot="icon" type="question-circle-o" style="color: red" />
            <a href="javascript:;" style="color: red">删除</a>
          </a-popconfirm>
        </span>
      </span>
    </v-table>
  </a-card>
</template>

<script>
import { fetchList, del } from '@api/app/version'
import { TableMixin } from '@/mixins/TableMixin'
export default {
  name: 'AppVersion',
  mixins: [TableMixin],
  data () {
    return {
      columns: [
        {
          title: '版本',
          field: 'version'
        },
        {
          title: 'build',
          field: 'build'
        },
        {
          title: '地址',
          field: 'url'
        },
        {
          title: '包名',
          field: 'bundleId'
        },
        {
          title: '创建时间',
          field: 'createTime'
        },
        {
          title: '操作',
          width: '200px',
          field: 'action',
          slot: true
        }

      ],
      queryParam: {
        version: ''
      },
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    deleteItem (record) {
      del(record.id).then(res => {
        this.$message.success('删除成功')
        this.queryPage()
      })
    }
  }
}
</script>

<style scoped>

</style>
